;$(function(){
  var data = {
    url: document.referrer,
    view: document.URL
  };
  // $.ajax({
  //   type: 'GET',
  //   data: {data: data},
  //   url: objSite.so_domain + 'user/log_behavior',
  //   dataType: 'jsonp',
  // })
});


// 全站发券
function addCoupon(trigger_page, trigger_behavior, trigger_url) {
  if (!trigger_url) {
    trigger_url = window.location.href;
  }
  objSite.ajaxUser('/coupon/add_coupon/', { trigger_page: trigger_page, trigger_behavior: trigger_behavior, trigger_url: trigger_url }, function (res) {
    if (res.status == 1) {
      var num = parseInt(res.data.count);
      if (num > 0) {
        addCouponDetails(num, res.data.list);
      }
    } else if (res.msg == '请登录') {
      return false;
    }
  });
}

function addCouponDetails(num, list) {
  var couponSum = num / 2;
  var couponHeight = 150 + 160 * Math.ceil(couponSum);
  var couponWidth = '730px';
  var couponSkin = 'coupon-openList';
  if (num == 1) {
    couponWidth = '385px';
    couponSkin = 'white-single';
  }
  var couponHtml = "";
  couponHtml += '<div class="user-open-coupon">\n                        <h3 class="white-title"></h3>\n                        <ul class="open-coupon-list clearfix">';
  //      全部领用券
  var typeClass = '';
  var linkHtml = '';
  for (var i = 0; i < list.length; i++) {
    if (list[i].type == 1) {
      typeClass = 'coupon-curriculum';
    }
    if (list[i].type == 2) {
      typeClass = 'coupon-download';
    }
    if (list[i].type == 3) {
      typeClass = 'coupon-vr';
    }
    linkHtml = '';
    if (list[i].link_url) {
      linkHtml = '<a href="' + list[i].link_url + '" target="_blank">\u53BB\u4F7F\u7528</a>';
    }
    couponHtml += '\n                            <li class="' + typeClass + ' clearfix">\n                                <div class="open-coupon-gen">\n                                    <p>' + list[i].coupon_price + ' <span>' + list[i].unit + '</span></p>\n                                </div>\n                                <div class="open-coupon-det">\n                                    <h4><span>' + list[i].coupon_title + '</span></h4>\n                                    <p>' + list[i].coupon_info + '</p>\n                                    <div class="open-coupon-item">\n                                        <span>' + list[i].end_time + ' \u5230\u671F</span>\n                                        ' + linkHtml + '\n                                    </div>\n                                </div>\n                            </li>';
  }
  couponHtml += '</ul></div>';
  layer.open({
    title: false,
    closeBtn: 0,
    btn: ['关闭', '立即查看'],
    skin: couponSkin, //加上边框coupon-openList
    area: [couponWidth, couponHeight + 'px'], //宽高
    content: couponHtml,
    btn2: function btn2() {
      //确定按钮
      //do something;
      location.href = objSite.getUserUrl('/coupon/index/index');
    }
  });
}
